package org.example;

import org.junit.jupiter.api.Test;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        Solution solution = new Solution();
        String s = solution.removeStars("erase******");
        System.out.println(s);
    }
}
/*class Solution {
    public String longestPalindrome(String s) {
        if (s.length() == 0 || s == null) {
            return "";
        }

        int strLen = s.length();
        int len = 1;
        int left = 0;
        int right = 0;
        int maxLen = 1;
        int maxStart = 0;
        for (int i = 0; i < strLen; i++) {
            left = i - 1;
            right = i + 1;
            while (left >= 0 && s.charAt(i) == s.charAt(left)) {
                left--;
                len++;
            }
            while (right < strLen && s.charAt(right) == s.charAt(i)) {
                right++;
                len++;
            }
            while (left >= 0 && right < strLen && s.charAt(left) == s.charAt(right)) {
                len += 2;
                left--;
                right++;
            }
            if (len > maxLen) {
                maxLen = len;
                maxStart = left;
            }
            len = 1;

        }
        return s.substring(maxStart + 1, maxStart + maxLen + 1);
    }
}*/

class Solution {

    public String removeStars(String s) {
        int strLen=s.length();

        while (s.contains("*")) {
            if (s.replace("*", "").isEmpty()) {
                return "";
            }
            int i;
            for( i=0;i<strLen;i++){
                if(s.charAt(i)=='*'&&i-1>=0&&i+1<=strLen){
                    s=s.substring(0,i-1)+s.substring(i+1,strLen);
                    strLen=strLen-2;
                    i=0;
                }
            }



        }
        return s;
    }
}
/*

if (s == null || s.length() == 0) {
        return "";
        }
int strLen = s.length();
int left = 0;
int right = 0;
int len = 1;
int maxStart = 0;
int maxLen = 0;

        for (int i = 0; i < strLen; i++) {
left = i - 1;
right = i + 1;
        while (left >= 0 && s.charAt(left) == s.charAt(i)) {
len++;
left--;
        }
        while (right < strLen && s.charAt(right) == s.charAt(i)) {
len++;
right++;
        }
        while (left >= 0 && right < strLen && s.charAt(right) == s.charAt(left)) {
len = len + 2;
left--;
right++;
        }
        if (len > maxLen) {
maxLen = len;
maxStart = left;
            }
len = 1;
        }
        return s.substring(maxStart + 1, maxStart + maxLen + 1);
    }*/
